import sqlobject


sqlobject.sqlhub.processConnection = sqlobject.connectionForURI("sqlite:/tmp/foo.db")


class CodePoint(sqlobject.SQLObject):
    name = sqlobject.StringCol()
    #codepointID = sqlobject.IntCol()
    #lineNum = sqlobject.IntCol()
    nodes = sqlobject.MultipleJoin('NodeInfo')
    nameIndex = sqlobject.DatabaseIndex('name')

class NodeInfo(sqlobject.SQLObject):
    codePoint = sqlobject.ForeignKey('CodePoint')
    offset = sqlobject.IntCol()
    endoffset = sqlobject.IntCol()
    timestamp = sqlobject.IntCol()
    offsetIndex = sqlobject.DatabaseIndex('offset', 'endoffset')
    timestampIndex = sqlobject.DatabaseIndex('timestamp')

CodePoint.createTable(ifNotExists = True)
NodeInfo.createTable(ifNotExists = True)

#cp = CodePoint(name = "moshe")
#ci1 = NodeInfo(codePoint = cp, offset = 2, endoffset = 20, timestamp = 12345)
#ci2 = NodeInfo(codePoint = cp, offset = 4, endoffset = 2, timestamp = 12345)
#ci3 = NodeInfo(codePoint = cp, offset = 6, endoffset = 4, timestamp = 12345)

#print cp.nodes
#q = NodeInfo.select((NodeInfo.q.offset >= 5) & (NodeInfo.q.offset <= 10))
#print list(q)




